#ifndef _CONSOLE_H_
#define _CONSOLE_H_
#include <windows.h>
#include <iostream>
#include <assert.h>
enum eConsoleColor
{
	FG_RED     = ( FOREGROUND_RED   | FOREGROUND_INTENSITY ),
	FG_GREEN   = ( FOREGROUND_GREEN | FOREGROUND_INTENSITY ),
	FG_BLUE    = ( FOREGROUND_BLUE  | FOREGROUND_INTENSITY ),
	FG_YELLOW  = ( FG_RED   | FG_GREEN ),
	FG_PINK    = ( FG_RED   | FG_BLUE ),
	FG_SKYBLUE = ( FG_GREEN | FG_BLUE ),
	FG_WHITE   = ( FG_RED   | FG_GREEN | FG_BLUE ),

	BG_GRAY    = ( BACKGROUND_INTENSITY ),
	BG_RED     = ( BACKGROUND_RED   | BACKGROUND_INTENSITY ),
	BG_GREEN   = ( BACKGROUND_GREEN | BACKGROUND_INTENSITY ),
	BG_BLUE    = ( BACKGROUND_BLUE  | BACKGROUND_INTENSITY ),
	BG_YELLOW  = ( BG_RED | BG_GREEN ),
	BG_PINK    = ( BG_RED | BG_BLUE ),
	BG_SKYBLUE = ( BG_GREEN | BG_BLUE ),
	BG_WHITE   = ( BG_RED | BG_GREEN | BG_BLUE ),
};

enum eLOG_LEVEL
{
	LOG_LEVEL_ETC,			// etc
	LOG_LEVEL_INFO,			// *
	LOG_LEVEL_WARNING,		// !
	LOG_LEVEL_ERROR,		// #
	LOG_LEVEL_IMPORTANT,
	LOG_LEVEL_MAX_NUM,
};

struct SLogType
{
	bool	isHide;
	WORD	color;
};	

enum eLOG_DEF
{
		LOG_TYPE_MAX_NUM		= 30,
};

class CConsole
{
public:
	CConsole(void);
	CConsole( const char * cszTitle );
	CConsole( const char * cszTitle, const char * strLogFilename );
	~CConsole(void);

	bool Create( const char * cszTitle );

	bool Create( const char * cszTitle,
				const char * strLogFileName,
				WORD wInfoMsgColor = ( FG_RED | BG_WHITE ),
				WORD wWarnMsgColor = ( FG_SKYBLUE ),
				WORD wErrorMsgColor = (FG_YELLOW),
				WORD wEtcMsgColor = ( FG_WHITE | BG_GRAY ) );

	void Destroy();

	bool IsShowLog( unsigned int  iLogType );

	void SetLogColor( unsigned int iLogType, WORD  color );

	bool MakeLogFile( const char* cszFileName );

	void Write( UINT logType, const char*    szFmt ... );

	void Write( UINT logType, const wchar_t* szFmt ... );

	void Write( const char * szFmt, ... );

	void Write( const wchar_t * szFmt, ... );

	HANDLE GetHandle () const { return m_hConsole; };

	void SetConsoleColor( WORD color );
	
	void ApplyBackColor( char cLogFirstByte );

	void SetBackgroundColor( WORD color );
	
protected:
	
	void clear();

	SLogType	m_logType  [ LOG_TYPE_MAX_NUM ];

	WORD	m_backColor[ LOG_LEVEL_MAX_NUM ];

	WORD	m_curColor;

	WORD	m_curBackColor;

	HANDLE	m_hConsole;

	bool	m_isLogFile;

	FILE*	m_logFP;
};

#ifdef _DEBUG

#define CREATE_DBGCONSOLE	GetDbgConsole
#define DBG_WRITE_CONSOLE	GetDbgConsole()->Write
#define DBG_START_FUNCTION()  DBG_WRITE_CONSOLE( LOG_LEVEL_INFO, "%s, Start \n",__FUNCTION__ )
#define DBG_EXIT_FUNCTION()  DBG_WRITE_CONSOLE( LOG_LEVEL_INFO, "%s, Exit \n",__FUNCTION__ )

__inline 

CConsole* GetDbgConsole()
{
	static CConsole s_console_instance;
	static bool		s_bCreated = false;

	if ( s_bCreated == false )
	{
		s_console_instance.Create("console");
		s_console_instance.MakeLogFile("log.log");
	}

	return &s_console_instance;
}

#else

__inline
CConsole *	CREATE_DBGCONSOLE()										{ return NULL; }
__inline
VOID				DBG_WRITE_CONSOLE( wchar_t * fmt, ... )	{}
__inline
VOID				DBG_WRITE_CONSOLE( char * fmt, ... )	{}
__inline
VOID				DBG_START_FUNCTION()					{}
__inline
VOID				DBG_EXIT_FUNCTION()						{}


#endif


#endif

